#!/bin/bash
echo "开始安装node-exporter..."
rm -rf /usr/share/node-exporter >/dev/null 2>&1

cd /usr/tmp
curl -L https://gitee.com/yadeno/node-exporter/raw/master/node_exporter-1.2.2.linux-amd64.tar.gz
if [[ $(echo $?) -eq 0 ]];then
    tar -xvf /usr/tmp/node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/share/

    mv /usr/share/node_exporter-1.2.2.linux-amd64 /usr/share/node-exporter

    chmod +x /usr/share/node-exporter/*

cat > /etc/systemd/system/node-exporter.service <<EOF
[Unit]
Description=Promethues Node Exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/share/node-exporter/node_exporter --web.listen-address=:19004  --no-collector.arp --no-collector.bcache --no-collector.bonding --no-collector.conntrack --no-collector.hwmon --no-collector.infiniband
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

    systemctl daemon-reload
    systemctl enable node-exporter

    systemctl start node-exporter

    echo "安装完成..."

else
    echo "下载文件失败，请重试。。"

fi